<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1 , minimum-scale=1.0,maximum-scale =1.0,user-scalable=no">
<title>更换结算卡</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
<style>
body {
	padding: 0;
	margin: 0;
}

#head {
	text-align: center;
	padding-top: 2%;
	margin-top: 5%
}

#center {
	text-align: center;
	padding-top: 2%;
	margin-top: 5%
}

.font-card {
	text-align: center;
	padding-top: 2%;
	color: #bababa;
	margin-top: 3%;
	font-size: 14px
}

.detail-top {
	border-bottom: solid 1px #ccc;
	height: 30px;
	padding-top: 6%;
}

.detail-real {
	float: left;
	margin-left: 3%;
	font-size: 16px
}

.detail-input input {
	border-style: none;
	margin-left: -15%;
	font-size: 14px
}

.detail-input {
	margin-left: 35%;
	width: 30%;
}

.pic {
	float: left;
	position: absolute;
	margin-left: 95%;
	top: 55%
}

.updown {
	padding-top: 5%;
}

.updown img {
	width: 85%;
	height: 40px;
	margin-top: -3%;
}

.anzhuan {
	position: relative;
	margin-top: -8%;
	font-size: 18px;
	color: #FFF;
}
</style>
<script lang="javascript" src="../js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="../js/layer/layer.js"></script>
<link rel="stylesheet" href="../js/layer/skin/layer.css" id="layuicss-skinlayercss">
<script type="text/javascript">
	window.onload = function() {
		$("#id_name").val(localStorage.getItem("ll_id_name"));
	}

	function bang() {
		var openID = localStorage.getItem("ll_openID");
		var card_no = $("#card_no").val();
		var bank_phone = $("#bank_phone").val();
		
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //手机号验证规则  
		//判断
		if (bank_phone == "" || card_no == "") {
			layer.msg("所有信息必须填写完整！");
			return;
		}
		
		if (!reg.test(bank_phone.trim())) {
			layer.msg("手机号验证失败，请核对后再提交！");
			return;
		}
		
		var bankCheck = luhmCheck(card_no);
		if(bankCheck == false){
			layer.msg("银行卡验证失败,请核对后再提交！");
			return;
		}
		$.ajax({
			url : '../llPay/changeDebit',
			type : 'post',
			data : {
				'openID' : openID,
				'card_no' : card_no,
				'bank_phone' : bank_phone
			},
			success : function(res) {
				if(res.result == "success"){
					layer.msg("更改成功！");
					window.location.href = "jiesuanyinhangka.html";
				}else{
					layer.msg("更改失败：" + res.message);
				}
			}
		})
	}
	
	//bankno为银行卡号 banknoInfo为显示提示信息的DIV或其他控件  
	function luhmCheck(bankno){  
	    var lastNum=bankno.substr(bankno.length-1,1);//取出最后一位（与luhm进行比较）  
	   
	    var first15Num=bankno.substr(0,bankno.length-1);//前15或18位  
	    var newArr=new Array();  
	    for(var i=first15Num.length-1;i>-1;i--){    //前15或18位倒序存进数组  
	        newArr.push(first15Num.substr(i,1));  
	    }  
	    var arrJiShu=new Array();  //奇数位*2的积 <9  
	    var arrJiShu2=new Array(); //奇数位*2的积 >9  
	       
	    var arrOuShu=new Array();  //偶数位数组  
	    for(var j=0;j<newArr.length;j++){  
	        if((j+1)%2==1){//奇数位  
	            if(parseInt(newArr[j])*2<9)  
	            arrJiShu.push(parseInt(newArr[j])*2);  
	            else  
	            arrJiShu2.push(parseInt(newArr[j])*2);  
	        }  
	        else //偶数位  
	        arrOuShu.push(newArr[j]);  
	    }  
	       
	    var jishu_child1=new Array();//奇数位*2 >9 的分割之后的数组个位数  
	    var jishu_child2=new Array();//奇数位*2 >9 的分割之后的数组十位数  
	    for(var h=0;h<arrJiShu2.length;h++){  
	        jishu_child1.push(parseInt(arrJiShu2[h])%10);  
	        jishu_child2.push(parseInt(arrJiShu2[h])/10);  
	    }          
	       
	    var sumJiShu=0; //奇数位*2 < 9 的数组之和  
	    var sumOuShu=0; //偶数位数组之和  
	    var sumJiShuChild1=0; //奇数位*2 >9 的分割之后的数组个位数之和  
	    var sumJiShuChild2=0; //奇数位*2 >9 的分割之后的数组十位数之和  
	    var sumTotal=0;  
	    for(var m=0;m<arrJiShu.length;m++){  
	        sumJiShu=sumJiShu+parseInt(arrJiShu[m]);  
	    }  
	       
	    for(var n=0;n<arrOuShu.length;n++){  
	        sumOuShu=sumOuShu+parseInt(arrOuShu[n]);  
	    }  
	       
	    for(var p=0;p<jishu_child1.length;p++){  
	        sumJiShuChild1=sumJiShuChild1+parseInt(jishu_child1[p]);  
	        sumJiShuChild2=sumJiShuChild2+parseInt(jishu_child2[p]);  
	    }        
	    //计算总和  
	    sumTotal=parseInt(sumJiShu)+parseInt(sumOuShu)+parseInt(sumJiShuChild1)+parseInt(sumJiShuChild2);  
	       
	    //计算Luhm值  
	    var k= parseInt(sumTotal)%10==0?10:parseInt(sumTotal)%10;          
	    var luhm= 10-k;  
	       
	    if(lastNum==luhm && lastNum.length != 0){  
	       //$("#banknoInfo").html("Luhm验证通过");  
	       return true;  
	    }  
	    else{  
	       //$("#banknoInfo").html("银行卡号必须符合Luhm校验");  
	       return false;  
	    }          
	}  
</script>
</head>
<body>
	<div id="head">
		<img src="../img/schedule2.png">
	</div>

	<div id="center">
		<img src="../img/img_Bank_card.png">
	</div>

	<div class="font-card">
		<span>请填写认证信息</span>
	</div>

	<div class="detail-top">
		<div class="detail-real">持卡人</div>
		<div class="detail-input">
			<input type="text" placeholder="请填写持卡人姓名" id="id_name" readonly="readonly">
		</div>
	</div>
	<div class="detail-top">
		<div class="detail-real">银行卡号</div>
		<div class="detail-input">
			<input type="text" placeholder="请输入银行卡号" id="card_no">
		</div>
	</div>
	<!-- <div class="detail-top">
            <div class="detail-real">手机号</div>
            <div class="detail-input"><input type="text" placeholder="" id="userPhone"></div>
        </div> -->
	<div class="detail-top">
		<div class="detail-real">预留手机</div>
		<div class="detail-input">
			<input type="text" placeholder="请输入预留手机号" id="bank_phone">
		</div>
	</div>
	<div class="out-side" style="text-align:center;margin-top: 40px;" onclick="bang()">
		<div class="updown">
			<img src="../img/btn.png">
		</div>
		<div class="anzhuan">
			<span>确认提交</span>
		</div>
	</div>


</body>
</html>